<form id="auto-data-form" action="role/saveOrUpdate" class="form-horizontal bv-form printArea" method="post" role="form" data-interceptor="_on_submit">
<div class="row">
	<div  class="col-sm-5">
		<div id="hd-div" style="display: none;">
			<input id="model.id" name="model.id" value="#(model.id)" placeholder="角色主键" type="hidden" />
		</div>
			
		<div class="form-group">
			<label for="model.code" class="col-sm-3 control-label">角色代码</label>
			<div class="col-sm-9">
				<input id="model.code" name="model.code" value="#(model.code)" placeholder="角色代码" #if(model.id)readonly="readonly" #end class="form-control input-md" required maxlength="64"/>
			</div>
		</div>
		
		<div class="form-group">
			<label for="model.name" class="col-sm-3 control-label">角色名称</label>
			<div class="col-sm-9">
				<input id="model.name" name="model.name" value="#(model.name)" placeholder="角色名称" class="form-control input-md" required maxlength="64"/>
			</div>
		</div>
		
		<div class="form-group">
			<label for="model.type" class="col-sm-3 control-label">角色类型</label>
			<div class="col-sm-9">
				 #@dict_select("model.type",model.type,"ROLE_TYPE",false,"角色类型","required")
			</div>
		</div>
		
		<div class="form-group">
			<label for="model.state" class="col-sm-3 control-label">角色状态</label>
			<div class="col-sm-9">
				#@dict_select("model.state",model.state,"DATA_STATE",false,"角色状态","required")
			</div>
		</div>
		
		<div class="form-group">
			<label for="model.sort" class="col-sm-3 control-label">排序号</label>
			<div class="col-sm-9">
				<input id="model.sort" name="model.sort" value="#(model.sort)" placeholder="排序" class="form-control input-md" required data-bv-integer maxlength="10" type="number"/>
			</div>
		</div>
		
		<div class="form-group">
			<label for="model.remark" class="col-sm-3 control-label">角色描述</label>
			<div class="col-sm-9">
				<textarea id="model.remark" name="model.remark" placeholder="描述" class="form-control input-md" maxlength="1024">#(model.remark)</textarea>
			</div>
		</div>
	</div>
	<div  class="col-sm-7">
		<ul id="ztree_ul" class="ztree"></ul>
	</div>
</div>
</form>
<script type="text/javascript">
	var ztree_id = "ztree_ul";
	var zTreeObj =null;
	function _auth_chk(ch){
		ch=$(ch);
		var parent=ch.parents("li:first");
		if("all"==ch.val()){
			parent.find("input[type='checkbox'][value!='all']").prop("disabled",ch.prop("checked"));
		}
		var treeNode =zTreeObj.getNodeByTId(ch.data("tid"));
		zTreeObj.checkNode(treeNode,parent.find("input[type='checkbox']:checked").length>0,true);
	}
	function _on_submit(){
		var nodes = zTreeObj.getCheckedNodes();
		var div=$("#hd-div");
		div.find("input[name='res_item']").remove();
		for(var i=0;i<nodes.length;i++){
			var node=nodes[i];
			//console.log(node.id+node.name)
			div.append("<input name='res_item' value='"+node.id+"' type='hidden'>");
			$("#" + node.tId+" input[type='checkbox']:not([disabled]):checked").each(function(){
				div.append("<input name='res_item' value='"+node.id+";"+this.value+"' type='hidden'>");
			});
		}
		return true;
	}
	
	$(document).ready(function() {
		
		var _ztreeSetting = {
				data : {
					simpleData : {
						enable : true
					}
				},
				check: {    
                    enable: true  
                } ,
				view : {
					addDiyDom : function addDiyDom(treeId, treeNode) {
						var auths=treeNode.attributes.auths;
						var authChecked=treeNode.attributes.authChecked;
						for(var i=0;i<auths.length;i++){
							var au=auths[i]
							var cid=treeNode.id+"|"+au.code;
							var html="<div class='checkbox checkbox-inline' style='padding-top:2px;'> <input type='checkbox' id='"+cid+"' value='"+au.code+"' data-tid='"+treeNode.tId+"' onclick='_auth_chk(this);' "+($.inArray(au.code, authChecked)!=-1?"checked":"")+"><label for='"+cid+"'>"+au.name+"</label> </div>";
							var aObj = $("#" + treeNode.tId + "_a").after(html);
						}
					}
				},
				callback : {
					onCheck : function(e, treeId, treeNode) {
						if(!treeNode.checked){
							$("#" + treeNode.tId+" input[type='checkbox']").prop("checked",false);
						}
					}
				}
			};
		zTreeObj=$.fn.zTree.init($("#" + ztree_id), _ztreeSetting,#(resources));
	});
</script>